package wordit;

import java.util.LinkedList;
import java.util.List;

public class LetterSequence {

	private final List<Letter> sequence;

	public LetterSequence() {
		this.sequence = new LinkedList<Letter>();
	}
	
	public double getScore(Dictionary dictionary) {
		double score;
		
		score = dictionary.scoreWord(getWord());
		score *= getSumOfLetterValues();
		score *= getLength();
		
		return score;
	}

	private int getSumOfLetterValues() {
		int sum=0;
		
		for (Letter l : sequence) {
			sum += l.getValue();
		}
		
		return sum;
	}

	private String getWord() {
		StringBuilder sb = new StringBuilder();
		
		for (Letter l : sequence) {
			sb.append(l.getLetter());
		}
		
		return sb.toString();
	}

	public int getLength() {
		return sequence.size();
	}

	public void addLetter(Letter l) {
		sequence.add(l);
	}

	public String toString() {
		return getWord();
	}
}
